<?php
    #-------------------------------------------------------------#
	# This file is part of the Kumomado - Virtual Window Platform #
	# for PHP. (c) 2009 Tsai, Min Che <tirme0812@gmail.com>       #
	# Please visit http://www.kumomado.org/ for more information. #
	#                                                             #
	# This software is licensed under the GNU License v3. Please  #
	# view the LICENSE file for the full text of this license.    #
    #-------------------------------------------------------------#

	/**
	 * @package libraries/
	 * @author Tsai, Min Che
	 * @version 1.0
	 */
	class KumomadoLibrary {
		/**
		 * Construct
		 */
		public function __construct() {}
		/**
		 * Load class from Kumomado framework
		 * @param string $class
		 */
		public function load($class) {
			static $loader = null;
			if ($loader == null) {
				$loader = new KumomadoLoader();
			}
			$loader->load($class);
		}
		/**
		 * Get the database connection
		 * @staticvar array $db
		 * @param string $name[option]
		 * @return object @link KumomadoDatabase
		 */
		public function db($name = 'default') {
			static $db = null;
			if ($db == null) {
				$db_config = $this->config('db')->get();
				foreach ($db_config as $key => $config) {
					Kumomado::load('Database.'.strtolower($config['db']).'.'.$config['db']);
					if (class_exists($config['db'])) {
						$db[$key] = new $config['db']($config);
						$db[$key]->connect();
					}
				}
			}
			if (isset($db[$name])) {
				return $db[$name];
			}
			if (isset($db['default'])) {
				return $db['default'];
			} else {
				throw new KumomadoLibraryException('The database config not setting.('.KUMOMADO_CONFIG_PATH.'db.config.php)');
				return false;
			}
		}
		/**
		 * Load language definition
		 * @param string $source_file[option]
		 * @param string $source_package[option]
		 * @param string $language[option]
		 * @return object @link KumomadoLanguage
		 */
		public function lang($source_file = '', $source_package = '', $language = null) {
			return new KumomadoLanguage($source_file, $source_package, $language);
		}
		/**
		 *
		 * @return object @link KumomadoConfig
		 */
		public function config($name = null) {
			return new KumomadoConfig($name);
		}
		public function logger() {
			return KumomadoLogger::getInstance();
		}
	}
?>